package example

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/example"
    exampleReq "github.com/flipped-aurora/gin-vue-admin/server/model/example/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type BwAssessmentTasksApi struct {}



// CreateBwAssessmentTasks 创建考核任务
// @Tags BwAssessmentTasks
// @Summary 创建考核任务
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body example.BwAssessmentTasks true "创建考核任务"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /bwAssessmentTasks/createBwAssessmentTasks [post]
func (bwAssessmentTasksApi *BwAssessmentTasksApi) CreateBwAssessmentTasks(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var bwAssessmentTasks example.BwAssessmentTasks
	err := c.ShouldBindJSON(&bwAssessmentTasks)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = bwAssessmentTasksService.CreateBwAssessmentTasks(ctx,&bwAssessmentTasks)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteBwAssessmentTasks 删除考核任务
// @Tags BwAssessmentTasks
// @Summary 删除考核任务
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body example.BwAssessmentTasks true "删除考核任务"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /bwAssessmentTasks/deleteBwAssessmentTasks [delete]
func (bwAssessmentTasksApi *BwAssessmentTasksApi) DeleteBwAssessmentTasks(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	id := c.Query("id")
	err := bwAssessmentTasksService.DeleteBwAssessmentTasks(ctx,id)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteBwAssessmentTasksByIds 批量删除考核任务
// @Tags BwAssessmentTasks
// @Summary 批量删除考核任务
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /bwAssessmentTasks/deleteBwAssessmentTasksByIds [delete]
func (bwAssessmentTasksApi *BwAssessmentTasksApi) DeleteBwAssessmentTasksByIds(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	ids := c.QueryArray("ids[]")
	err := bwAssessmentTasksService.DeleteBwAssessmentTasksByIds(ctx,ids)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateBwAssessmentTasks 更新考核任务
// @Tags BwAssessmentTasks
// @Summary 更新考核任务
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body example.BwAssessmentTasks true "更新考核任务"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /bwAssessmentTasks/updateBwAssessmentTasks [put]
func (bwAssessmentTasksApi *BwAssessmentTasksApi) UpdateBwAssessmentTasks(c *gin.Context) {
    // 从ctx获取标准context进行业务行为
    ctx := c.Request.Context()

	var bwAssessmentTasks example.BwAssessmentTasks
	err := c.ShouldBindJSON(&bwAssessmentTasks)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = bwAssessmentTasksService.UpdateBwAssessmentTasks(ctx,bwAssessmentTasks)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindBwAssessmentTasks 用id查询考核任务
// @Tags BwAssessmentTasks
// @Summary 用id查询考核任务
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param id query int true "用id查询考核任务"
// @Success 200 {object} response.Response{data=example.BwAssessmentTasks,msg=string} "查询成功"
// @Router /bwAssessmentTasks/findBwAssessmentTasks [get]
func (bwAssessmentTasksApi *BwAssessmentTasksApi) FindBwAssessmentTasks(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	id := c.Query("id")
	rebwAssessmentTasks, err := bwAssessmentTasksService.GetBwAssessmentTasks(ctx,id)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(rebwAssessmentTasks, c)
}
// GetBwAssessmentTasksList 分页获取考核任务列表
// @Tags BwAssessmentTasks
// @Summary 分页获取考核任务列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query exampleReq.BwAssessmentTasksSearch true "分页获取考核任务列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /bwAssessmentTasks/getBwAssessmentTasksList [get]
func (bwAssessmentTasksApi *BwAssessmentTasksApi) GetBwAssessmentTasksList(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var pageInfo exampleReq.BwAssessmentTasksSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := bwAssessmentTasksService.GetBwAssessmentTasksInfoList(ctx,pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetBwAssessmentTasksPublic 不需要鉴权的考核任务接口
// @Tags BwAssessmentTasks
// @Summary 不需要鉴权的考核任务接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /bwAssessmentTasks/getBwAssessmentTasksPublic [get]
func (bwAssessmentTasksApi *BwAssessmentTasksApi) GetBwAssessmentTasksPublic(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    bwAssessmentTasksService.GetBwAssessmentTasksPublic(ctx)
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的考核任务接口信息",
    }, "获取成功", c)
}
